#include<cstdlib>
#include<cstdio>
#include<cstring>

#define FORMAT "[%s@%s %s]#"
#define COMMAND_SIZE 1024
#define MAXARGC 128

char* argv[argc];
int argc=0;
const char* GetName()
{
    const char* name=getenv("USER");
    return name==NULL?"None":name;
}
const char* GetHostName()
{
    const char* hostname=getenv("HOSTNAME");
    return hostname;
}
const char* GetPwd()
{
    const char* pwd=getenv("PWD");
    return pwd==NULL?"None":pwd;
}
void MakeCommandLine(char cmd_prompt[],int size)
{
   int ret= snprintf(cmd_prompt,size,FORMAT,GetName(),GetHostName(),GetPwd());
   (void)ret;
}
void PrintCommandLine()
{
    char prompt[COMMAND_SIZE];
    MakeCommandLine(prompt,sizeof(prompt));
    printf("%s",prompt);
    fflush(stdout);
}
bool GetCommandLine(char* out,int size)
{
  char* c=fgets(out,size,stdin);
  if(c==NULL) return false;
  out[sizeof(out)-1]=0;
  if(strlen(out)==0)return false;
  return true;
}
void CommandParse(char* commandline)
{

}
int main()
{
    PrintCommandLine();
    char commandline[COMMAND_SIZE];
    GetCommandLine(commandline,sizeof(commandline));

    //分析命令：
    CommandParse(commandline);
    int i=0;
    while(commandline[i]!=0)
    {
        printf("%c",commandline[i]);
        i++;
    }

    return 0;
}
